<?php
class ModelCatalogCheckingform extends Model {
	public function addUser($data) {
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "registration SET name = '" . $data['uname'] . "', fathername = '" . $data['fname'] . "',
		dob = '" .$data['datepicker'] . "', age = '" .$data['age'] . "',  mobile = '" . $data['mobile'] . "', phonenumber = '" . $data['phone'] . "', 
		email ='". $data['email']."', address ='". $data['address'] ."' ,city ='" .$data['city'] ."',
		district ='".$data['dist']."', pincode ='".$data['pin']."',  state = '".$data['state']."' ,
		country ='".$data['countries']."', refereed ='".$data['req']."', dateofvisit ='".$data['datepicker1']."', p_exit_or_not ='".$data['opt']."'");
		$user_id = $this->db->getLastId();
		return $user_id	;	
	}
	public function detailsState()
	{
		$query=$this->db->query("SELECT * FROM " . DB_PREFIX . "state ");
		return $query->rows;
	}
	public function detailsCountry ()
	{
		$query=$this->db->query("SELECT * FROM " . DB_PREFIX . "country ");
		return $query->rows;
	}
	public function getUserData() {
		$query=$this->db->query("SELECT * FROM " . DB_PREFIX . "registration ");
		return $query->rows;
	}
	public function editUserDetail($userid) {
		$sql=$this->db->query("SELECT * FROM " . DB_PREFIX . "registration WHERE p_id = '".$userid."' ");
		return $sql->row;
	}
	public function userDetails($userid) {
		
		$query=$this->db->query("SELECT * FROM " . DB_PREFIX . "registration WHERE p_id = '".$userid."' " );
		return $query->row;

		/*$query=$this->db->query("UPDATE  FROM " . DB_PREFIX ."registration SET name = '" . $data['uname'] . "', fathername = '" . $data['fname'] . "',
		dob = '" .$data['datepicker'] . "', age = '" .$data['age'] . "',  mobile = '" . $data['mobile'] . "', phonenumber = '" . $data['phone'] . "', 
		email ='". $data['email']."', address ='". $data['address'] ."' ,city ='" .$data['city'] ."', district ='".$data['dist']."', pincode ='".$data['pin']."',  state = '".$data['state']."' ,
		country ='".$data['countries']."', refereed ='".$data['req']."', dateofvisit ='".$data['datepicker1']."', p_exit_or_not ='".$data['opt']."' 
		WHERE p_id = '".$userid."'");
		return $query->rows;*/
	}
	public function updateUser($data) {
		$uid = base64_decode($data['hidUid']);
		
		$query=$this->db->query("UPDATE  " . DB_PREFIX ."registration SET name = '" . $data['uname'] . "', fathername = '" . $data['fname'] . "',
		dob = '" .$data['datepicker'] . "', age = '" .$data['age'] . "',  mobile = '" . $data['mobile'] . "', phonenumber = '" . $data['phone'] . "', 
		email ='". $data['email']."', address ='". $data['address'] ."' ,city ='" .$data['city'] ."', district ='".$data['dist']."', pincode ='".$data['pin']."',  state = '".$data['state']."' ,
		country ='".$data['countries']."', refereed ='".$data['req']."', dateofvisit ='".$data['datepicker1']."', p_exit_or_not ='".$data['opt']."' 
		WHERE p_id = '".$uid."'");
		return $query->row;
	
	}
	public function checkUser($uid,$position){
		if($position==1)
		{
			$position="pbefore";
		}
		else
		{
			$position="pafter";
		}
			echo "SELECT  ".$position." FROM " . DB_PREFIX . "registration WHERE p_id = '".$uid."' " ;
		$query=$this->db->query("SELECT  ".$position." FROM " . DB_PREFIX . "registration WHERE p_id = '".$uid."' " );
		return $query->row[$position];
	}
	public function getenvdetails($uid,$envarray,$position){
			$query=$this->db->query("SELECT  * FROM " . DB_PREFIX . "environmental WHERE p_id = '".$uid."' and environmental='".$envarray."' and position='".$position."'" );
			return $query->row;
	}
	
	public function getplantdetails($uid,$planetray,$position){
			$query=$this->db->query("SELECT  * FROM " . DB_PREFIX . "planetary WHERE p_id = '".$uid."' and planetray='".$planetray."' and position='".$position."'" );
			return $query->row;
	}
	public function getchacrasdetails($uid,$chakras,$position){
			$query=$this->db->query("SELECT  * FROM " . DB_PREFIX . "chakras WHERE p_id = '".$uid."' and chakras='".$chakras."' and position='".$position."'" );
			return $query->row;
	}
	public function addEnvDetailes($uid,$before,$environ)
	{
	
		//Environmental table
		$del=$this->db->query("DELETE FROM " . DB_PREFIX . "environmental WHERE p_id='" .$uid. "' and position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "environmental SET p_id = '" .$uid. "', environmental = '" . $environ['Geograph'] . "',
		status = '" .$environ['geo'] . "', lowangel = '" . $environ['geo_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "environmental SET p_id = '" .$uid. "', environmental = '" . $environ['Negative'] . "',
		status = '" .$environ['negative'] . "', lowangel = '" . $environ['negative_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "environmental SET p_id = '" .$uid. "', environmental = '" . $environ['Infrared'] . "',
		status = '" .$environ['infrared'] . "', lowangel = '" . $environ['infrared_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "environmental SET p_id = '" .$uid. "', environmental = '" . $environ['Sole_name'] . "',
		status = '" .$environ['Sole'] . "', lowangel = '" . $environ['Sole_low'] . "', position = '" . $before . "'");
		
		
		//Planatary Table
		$del=$this->db->query("DELETE FROM " . DB_PREFIX . "planetary WHERE p_id='" .$uid. "' and position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['The_Sun_name'] . "',
		status = '" .$environ['The_Sun'] . "', lowangel = '" . $environ['The_Sun_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Mercury_name'] . "',
		status = '" .$environ['Mercury'] . "', lowangel = '" . $environ['Mercury_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Venus_name'] . "',
		status = '" .$environ['Venus'] . "', lowangel = '" . $environ['Venus_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Earth_name'] . "',
		status = '" .$environ['Earth'] . "', lowangel = '" . $environ['Earth_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Mars_name'] . "',
		status = '" .$environ['Mars'] . "', lowangel = '" . $environ['Mars_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Jupiter_name'] . "',
		status = '" .$environ['Jupiter'] . "', lowangel = '" . $environ['Jupiter_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Saturn_name'] . "',
		status = '" .$environ['Saturn'] . "', lowangel = '" . $environ['Saturn_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Uranus_name'] . "',
		status = '" .$environ['Uranus'] . "', lowangel = '" . $environ['Uranus_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "planetary SET p_id = '" .$uid. "', planetray = '" . $environ['Neptune_name'] . "',
		status = '" .$environ['Neptune'] . "', lowangel = '" . $environ['Neptune_low'] . "', position = '" . $before . "'");
		
		
		//Chakrastable
		
		$del=$this->db->query("DELETE FROM " . DB_PREFIX . "chakras WHERE p_id='" .$uid. "' and position = '" . $before . "'");		
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Muladhra_name'] . "',
		status = '" .$environ['Muladhra'] . "', lowangel = '" . $environ['Muladhra_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Swadhistana_name'] . "',
		status = '" .$environ['Swadhistana'] . "', lowangel = '" . $environ['Swadhistana_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Naval_name'] . "',
		status = '" .$environ['Naval'] . "', lowangel = '" . $environ['Naval_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Solar_name'] . "',
		status = '" .$environ['Solar'] . "', lowangel = '" . $environ['Solar_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Front_name'] . "',
		status = '" .$environ['Solar'] . "', lowangel = '" . $environ['Solar_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Solar_name'] . "',
		status = '" .$environ['Front'] . "', lowangel = '" . $environ['Front_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Back_name'] . "',
		status = '" .$environ['Back'] . "', lowangel = '" . $environ['Back_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Throat_name'] . "',
		status = '" .$environ['Throat'] . "', lowangel = '" . $environ['Throat_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Ajna_name'] . "',
		status = '" .$environ['Ajna'] . "', lowangel = '" . $environ['Ajna_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Fore_name'] . "',
		status = '" .$environ['Fore'] . "', lowangel = '" . $environ['Fore_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Crown_name'] . "',
		status = '" .$environ['Crown'] . "', lowangel = '" . $environ['Crown_low'] . "', position = '" . $before . "'");
		
		$sql=$this->db->query("INSERT INTO " . DB_PREFIX . "chakras SET p_id = '" .$uid. "', chakras = '" . $environ['Spleen_name'] . "',
		status = '" .$environ['Spleen'] . "', lowangel = '" . $environ['Spleen_low'] . "', position = '" . $before . "'");
		
		$user_id = $this->db->getLastId();
		return $user_id	;
	}
}
?>